//
//  LQPhotoPickerViewController.m
//  LQPhotoPicker
//
//  Created by lawchat on 15/9/22.
//  Copyright (c) 2015年 Fillinse. All rights reserved.
//

#import "LGPhotoPickerController.h"
#import "LGPhotoCollectionCell.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "LQImgPickerActionSheet.h"
#import "JJPhotoManeger.h"

#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
#import "TZImagePickerController.h"
#import "TZImageManager.h"
#import "TZVideoPlayerController.h"
#import "TZPhotoPreviewController.h"
#import "TZGifPhotoPreviewController.h"
#import "TZLocationManager.h"
@interface LGPhotoPickerController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,LQImgPickerActionSheetDelegate,JJPhotoDelegate,UIActionSheetDelegate,TZImagePickerControllerDelegate,UIImagePickerControllerDelegate,UIAlertViewDelegate,UINavigationControllerDelegate>{
}
@property (nonatomic , strong)UICollectionView *collectionView;
@property (nonatomic , assign)CGFloat collectionFrameY;

@property (nonatomic , assign)BOOL isSelectOriginalPhoto;
@property (nonatomic , assign)CGFloat itemWH;
@property (nonatomic , assign)CGFloat margin;

//图片选择器
@property (nonatomic , strong)UIViewController *showActionSheetViewController;
@property (nonatomic , strong)CLLocation *location;
@property (nonatomic , strong)UIImagePickerController *imagePickerVc;
@end

@implementation LGPhotoPickerController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (!_showActionSheetViewController) {
        _showActionSheetViewController = self;
    }
    self.maxCount = 10;
    self.imageWidth = viewPix(70);
    self.imageHeight = viewPix(70);
    self.marginLeft = viewPix(15);
    self.marginRight = viewPix(30);
    self.marginTop = viewPix(10);
    self.marginV = viewPix(10);
}

- (void)LQPhotoPicker_initPickerView{
    if (_superView) {
        [self.superView addSubview:self.collectionView];
    }else{
        [self.view addSubview:self.collectionView];
    }
    //添加图片提示
    [self.collectionView addSubview:self.remindLabel];
    [self.collectionView addSubview:self.remindSubLabel];
//    CGFloat superWidth = (_superView)?self.superView.bounds.size.width:self.view.bounds.size.width;
//    CGFloat tempWidth = superWidth-self.marginLeft*2;
//    self.collectionView.frame = CGRectMake(self.marginLeft, self.marginTop, <#CGFloat width#>, <#CGFloat height#>)
}


-(void)setPushImgName:(NSString *)pushImgName{
    _pushImgName = pushImgName;
}

-(void)setImageWidth:(CGFloat)imageWidth{
    _imageWidth = imageWidth;
}

-(void)setImageHeight:(CGFloat)imageHeight{
    _imageHeight = imageHeight;
}

-(void)setMarginLeft:(CGFloat)marginLeft{
    _marginLeft = marginLeft;
}

-(void)setMarginRight:(CGFloat)marginRight{
    _marginRight = marginRight;
}
-(void)setMarginTop:(CGFloat)marginTop{
    _marginTop = marginTop;
}
-(void)setMarginV:(CGFloat)marginV{
    _marginV = marginV;
}



#pragma mark - 图片cell点击事件
- (void) tapProfileImage:(UITapGestureRecognizer *)gestureRecognizer{
    __weak typeof(self) weakSelf = self;
    UIImageView *tableGridImage = (UIImageView*)gestureRecognizer.view;
    NSInteger index = tableGridImage.tag;
    
    if (index == (_smallImageArray.count)) {
        [self.view endEditing:YES];
        //添加新图片
        [self addNewImg];
    }
    else{
        //点击放大查看
        //        LQPhotoViewCell *cell = (LQPhotoViewCell*)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
        //        if (!cell.BigImgView || !cell.BigImgView.image) {
        //
        //            [cell setBigImgViewWithImage:[self getBigIamgeWithALAsset:_selectedAssetArray[index]]];
        //        }
        //
        //        JJPhotoManeger *mg = [JJPhotoManeger maneger];
        //        mg.delegate = self;
        //        [mg showLocalPhotoViewer:@[cell.BigImgView] selecImageindex:index];
        TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_selectedAssetArray selectedPhotos:_smallImageArray index:index];
        imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
            weakSelf.smallImageArray = [NSMutableArray arrayWithArray:photos];
            weakSelf.selectedAssetArray = [NSMutableArray arrayWithArray:assets];
            weakSelf.isSelectOriginalPhoto = isSelectOriginalPhoto;
            [weakSelf.collectionView reloadData];
            weakSelf.collectionView.contentSize = CGSizeMake(0, ((weakSelf.smallImageArray.count + 2) / 3 ) * (weakSelf.margin + weakSelf.itemWH));
        }];
        imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:imagePickerVc animated:YES completion:nil];
    }
}

#pragma mark - 选择图片
- (void)addNewImg{
    if (self.smallImageArray.count == self.maxCount) {
        UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"提示" message:@"选择图片数量已达上限" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil];
        [controller addAction:action];
        [self presentViewController:controller animated:YES completion:nil];
        return;
    }else{
        UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self takePhoto];
        }];
        UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"去相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self pushTZImagePickerController];
        }];
        [controller addAction:cancelAction];
        [controller addAction:cameraAction];
        [controller addAction:photoAction];
        [self presentViewController:controller animated:YES completion:nil];
    }
}

#pragma mark - UIImagePickerController

- (void)takePhoto {
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied)) {
        //无相机权限 做一个友好的提示
        UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-红日医生端-相机""中允许访问相机" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *settingAction = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
        }];
        [controller addAction:cancelAction];
        [controller addAction:settingAction];
        [self presentViewController:controller animated:YES completion:nil];
    } else if (authStatus == AVAuthorizationStatusNotDetermined) {
        // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
        if (iOS7Later) {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (granted) {
                    dispatch_sync(dispatch_get_main_queue(), ^{
                        [self takePhoto];
                    });
                }
            }];
        } else {
            [self takePhoto];
        }
        // 拍照之前还需要检查相册权限
    } else if ([TZImageManager authorizationStatus] == 2) { // 已被拒绝，没有相册权限，将无法保存拍的照片
        //无相机权限 做一个友好的提示
        UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"无法使用相册" message:@"请在iPhone的""设置-红日医生端-照片""中允许访问照片" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *settingAction = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
        }];
        [controller addAction:cancelAction];
        [controller addAction:settingAction];
        [self presentViewController:controller animated:YES completion:nil];
    } else if ([TZImageManager authorizationStatus] == 0) { // 未请求过相册权限
        [[TZImageManager manager] requestAuthorizationWithCompletion:^{
            [self takePhoto];
        }];
    } else {
        [self pushImagePickerController];
    }
}

// 调用相机
- (void)pushImagePickerController {
    // 提前定位
    __weak typeof(self) weakSelf = self;
    [[TZLocationManager manager] startLocationWithSuccessBlock:^(CLLocation *location, CLLocation *oldLocation) {
        weakSelf.location = location;
    } failureBlock:^(NSError *error) {
        weakSelf.location = nil;
    }];
    
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        self.imagePickerVc.sourceType = sourceType;
        if(iOS8Later) {
            _imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        }
        [self presentViewController:_imagePickerVc animated:YES completion:nil];
    } else {
        NSLog(@"模拟器中无法打开照相机,请在真机中使用");
    }
}

#pragma mark - TZImagePickerController
- (void)pushTZImagePickerController {
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:self.maxCount columnNumber:3 delegate:self pushPhotoPickerVc:YES];
    imagePickerVc.isSelectOriginalPhoto = self.isSelectOriginalPhoto;
    imagePickerVc.selectedAssets = self.selectedAssetArray; // 目前已经选中的图片数组
    imagePickerVc.sortAscendingByModificationDate = YES;
    imagePickerVc.isStatusBarDefault = YES;
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        
        
    }];
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [picker dismissViewControllerAnimated:YES completion:nil];
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
        [tzImagePickerVc showProgressHUD];
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSLog(@"%@",self.location);
        
        // save photo and get asset / 保存图片，获取到asset
        [[TZImageManager manager] savePhotoWithImage:image location:self.location completion:^(NSError *error){
            if (error) {
                [tzImagePickerVc hideProgressHUD];
                NSLog(@"图片保存失败 %@",error);
            } else {
                [[TZImageManager manager] getCameraRollAlbum:NO allowPickingImage:YES completion:^(TZAlbumModel *model) {
                    [[TZImageManager manager] getAssetsFromFetchResult:model.result allowPickingVideo:NO allowPickingImage:YES completion:^(NSArray<TZAssetModel *> *models) {
                        [tzImagePickerVc hideProgressHUD];
                        TZAssetModel *assetModel = [models firstObject];
                        if (tzImagePickerVc.sortAscendingByModificationDate) {
                            assetModel = [models lastObject];
                        }
                        [self refreshCollectionViewWithAddedAsset:assetModel.asset image:image];
                    }];
                }];
            }
        }];
    }
}

- (void)refreshCollectionViewWithAddedAsset:(id)asset image:(UIImage *)image {
    [_selectedAssetArray addObject:asset];
    [_smallImageArray addObject:image];
    [_collectionView reloadData];
    
    if ([asset isKindOfClass:[PHAsset class]]) {
        PHAsset *phAsset = asset;
        NSLog(@"location:%@",phAsset.location);
    }
}
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
    _smallImageArray = [NSMutableArray arrayWithArray:photos];
    _selectedAssetArray = [NSMutableArray arrayWithArray:assets];
    _isSelectOriginalPhoto = isSelectOriginalPhoto;
    [_collectionView reloadData];
    // _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
    
    // 1.打印图片名字
    //    [self printAssetsName:assets];
    // 2.图片位置信息
    if (iOS8Later) {
        for (PHAsset *phAsset in assets) {
            NSLog(@"location:%@",phAsset.location);
        }
    }
}

-(BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result {
    /*
     if ([albumName isEqualToString:@"个人收藏"]) {
     return NO;
     }
     if ([albumName isEqualToString:@"视频"]) {
     return NO;
     }*/
    return YES;
}

// Decide asset show or not't
// 决定asset显示与否
- (BOOL)isAssetCanSelect:(id)asset {
    /*
     if (iOS8Later) {
     PHAsset *phAsset = asset;
     switch (phAsset.mediaType) {
     case PHAssetMediaTypeVideo: {
     // 视频时长
     // NSTimeInterval duration = phAsset.duration;
     return NO;
     } break;
     case PHAssetMediaTypeImage: {
     // 图片尺寸
     if (phAsset.pixelWidth > 3000 || phAsset.pixelHeight > 3000) {
     // return NO;
     }
     return YES;
     } break;
     case PHAssetMediaTypeAudio:
     return NO;
     break;
     case PHAssetMediaTypeUnknown:
     return NO;
     break;
     default: break;
     }
     } else {
     ALAsset *alAsset = asset;
     NSString *alAssetType = [[alAsset valueForProperty:ALAssetPropertyType] stringValue];
     if ([alAssetType isEqualToString:ALAssetTypeVideo]) {
     // 视频时长
     // NSTimeInterval duration = [[alAsset valueForProperty:ALAssetPropertyDuration] doubleValue];
     return NO;
     } else if ([alAssetType isEqualToString:ALAssetTypePhoto]) {
     // 图片尺寸
     CGSize imageSize = alAsset.defaultRepresentation.dimensions;
     if (imageSize.width > 3000) {
     // return NO;
     }
     return YES;
     } else if ([alAssetType isEqualToString:ALAssetTypeUnknown]) {
     return NO;
     }
     }*/
    return YES;
}
#pragma mark - 删除照片
- (void)deletePhoto:(UIButton *)sender{
    
    [_smallImageArray removeObjectAtIndex:sender.tag];
    [_selectedAssetArray removeObjectAtIndex:sender.tag];
    
    [self.collectionView reloadData];
//    [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:sender.tag inSection:0]]];
//
//    for (NSInteger item = sender.tag; item <= _smallImageArray.count; item++) {
//        LQPhotoViewCell *cell = (LQPhotoViewCell*)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]];
//        cell.closeButton.tag--;
//        cell.profilePhoto.tag--;
//    }
    //没有任何图片
//    if (_smallImageArray.count == 0) {
//        _addImgStrLabel.hidden = NO;
//    }
//    else{
//        _addImgStrLabel.hidden = YES;
//    }
//    [self changeCollectionViewHeight];
}

#pragma mark - LQImgPickerActionSheetDelegate (返回选择的图片：缩略图，压缩原长宽比例大图)
//- (void)getSelectImgWithALAssetArray:(NSArray*)ALAssetArray thumbnailImgImageArray:(NSArray*)thumbnailImgArray{
//
//    //（ALAsset）类型 Array
//    _selectedAssetArray = [NSMutableArray arrayWithArray:ALAssetArray];
//    //正方形缩略图 Array
//    _smallImageArray = [NSMutableArray arrayWithArray:thumbnailImgArray] ;
//
//    [self.collectionView reloadData];
//}

#pragma mark - 改变view，collectionView高度
- (void)changeCollectionViewHeight{
    self.collectionView.frame = CGRectMake(0, self.collectionFrameY, self.superView.bounds.size.width, (self.imageHeight+self.marginV)* ((int)(self.selectedAssetArray.count)/4 +1)-self.marginV+self.marginTop*2);
  
    if (self.delegate && [self.delegate respondsToSelector:@selector(collectionViewHeight:)]) {
        [self.delegate collectionViewHeight:self.collectionView.bounds.size.height];
    }
}

- (void)LQPhotoPicker_updatePickerViewFrameY:(CGFloat)Y{
    
    _collectionFrameY = Y;
    self.collectionView.frame = CGRectMake(0, self.collectionFrameY, self.superView.bounds.size.width, (self.imageHeight+self.marginV)* ((int)(self.selectedAssetArray.count)/4 +1)-self.marginV);
//    _collectionView.frame = CGRectMake(0, Y, Screen_W, (((float)Screen_W-topBarHeight) /4.0 +20.0)* ((int)(_selectedAssetArray.count)/4 +1)+20.0);
}

#pragma mark - 防止奔溃处理
-(void)photoViwerWilldealloc:(NSInteger)selecedImageViewIndex{
    NSLog(@"最后一张观看的图片的index是:%zd",selecedImageViewIndex);
}

- (NSData*)getBigIamgeDataWithALAsset:(ALAsset*)set{
    UIImage *img = [UIImage imageWithCGImage:set.defaultRepresentation.fullResolutionImage
                                       scale:set.defaultRepresentation.scale
                                 orientation:(UIImageOrientation)set.defaultRepresentation.orientation];
    
    return UIImageJPEGRepresentation(img, 0.5);
}
//- (UIImage*)getBigIamgeWithALAsset:(PHAsset*)set{
//    //压缩
//    // 需传入方向和缩放比例，否则方向和尺寸都不对
//
//    NSData *imageData = [self getBigIamgeDataWithALAsset:set];
//
//    [_LQPhotoPicker_bigImgDataArray addObject:imageData];
//
//    return [UIImage imageWithData:imageData];
//}

- (UIImage *)compressImage:(UIImage *)image toMaxFileSize:(NSInteger)maxFileSize {
    CGFloat compression = 0.9f;
    CGFloat maxCompression = 0.1f;
    NSData *imageData = UIImageJPEGRepresentation(image, compression);
    while ([imageData length] > maxFileSize && compression > maxCompression) {
        compression -= 0.1;
        imageData = UIImageJPEGRepresentation(image, compression);
    }
    
    UIImage *compressedImage = [UIImage imageWithData:imageData];
    return compressedImage;
}  


#pragma mark ====> UICollectionViewDataSource、Delegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.smallImageArray.count+1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    // Set up the reuse identifier
    LGPhotoCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: @"cell" forIndexPath:indexPath];
    
    if (indexPath.row == _smallImageArray.count) {
        [cell.photoView setImage:[UIImage imageNamed:_pushImgName]];
        cell.closeBtn.hidden = YES;
        
        //没有任何图片
        if (_smallImageArray.count == 0) {
            _remindLabel.hidden = NO;
            _remindSubLabel.hidden = NO;
        }
        else{
            _remindLabel.hidden = YES;
            _remindSubLabel.hidden = YES;
        }
    }
    else{
        [cell.photoView setImage:_smallImageArray[indexPath.item]];
        cell.closeBtn.hidden = NO;
    }
//    [cell setBigImgViewWithImage:nil];
    cell.photoView.tag = [indexPath item];
    
    //添加图片cell点击事件
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapProfileImage:)];
    singleTap.numberOfTapsRequired = 1;
    cell.photoView .userInteractionEnabled = YES;
    [cell.photoView  addGestureRecognizer:singleTap];
    cell.closeBtn.tag = [indexPath item];
    [cell.closeBtn addTarget:self action:@selector(deletePhoto:) forControlEvents:UIControlEventTouchUpInside];
    
    [self changeCollectionViewHeight];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(self.imageWidth ,self.imageHeight);
}


-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return self.marginV;
}

//定义每个UICollectionView 的 margin
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(self.marginTop, self.marginLeft, self.marginTop, self.marginRight);
}



#pragma mark - 获得选中图片各个尺寸
- (NSMutableArray*)LQPhotoPicker_getALAssetArray{
    return _selectedAssetArray;
}

- (NSMutableArray*)LQPhotoPicker_getBigImageArray{
    _bigImageArray = [NSMutableArray array];
//    _LQPhotoPicker_bigImgDataArray = [NSMutableArray array];
    //        for (PHAsset *set in _selectedAssetArray) {
    //                [_bigImageArray addObject:[self getBigIamgeWithALAsset:set]];
    //
    //            }
    
    for (UIImage *ima in _smallImageArray) {
        [_bigImageArray addObject:ima];
    }
    return _bigImageArray;
}

//- (NSMutableArray*)LQPhotoPicker_getBigImageDataArray{
//    _bigImageArray = [NSMutableArray array];
//        _LQPhotoPicker_bigImgDataArray = [NSMutableArray array];
//        for (ALAsset *set in _selectedAssetArray) {
//            [_bigImageArray addObject:[self getBigIamgeWithALAsset:set]];
//        }
//
//    return _LQPhotoPicker_bigImgDataArray;
//}

- (NSMutableArray*)LQPhotoPicker_getSmallImageArray{
    return _smallImageArray;
}
//- (NSMutableArray*)LQPhotoPicker_getSmallDataImageArray{
//    _LQPhotoPicker_smallDataImageArray = [NSMutableArray array];
//        for (UIImage *smallImg in _smallImageArray) {
//            NSData *smallImgData = UIImagePNGRepresentation(smallImg);
//            [_LQPhotoPicker_smallDataImageArray addObject:smallImgData];
//        }
//    return _LQPhotoPicker_smallDataImageArray;
//}
- (CGRect)LQPhotoPicker_getPickerViewFrame{
    return self.collectionView.frame;
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (NSMutableArray*)LQPhotoPicker_getSmallDataImageArray{
    return nil;
}

- (NSMutableArray*)LQPhotoPicker_getBigImageDataArray{
    return nil;
}

- (BOOL)prefersStatusBarHidden{
    return NO;
}
#pragma mark
#pragma mark ====> 懒加载
-(NSMutableArray *)smallImageArray{
    if(!_smallImageArray){
        _smallImageArray = [NSMutableArray array];
    }
    return _smallImageArray;
}

-(NSMutableArray *)bigImageArray{
    if(!_bigImageArray){
        _bigImageArray = [NSMutableArray array];
    }
    return _bigImageArray;
}
    
 
- (UIImagePickerController *)imagePickerVc{
    if (_imagePickerVc == nil) {
        _imagePickerVc = [[UIImagePickerController alloc] init];
        _imagePickerVc.delegate = self;
        UIBarButtonItem *tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
        UIBarButtonItem *BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
        NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
        [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
    }
    return _imagePickerVc;
}
    
-(UICollectionView *)collectionView{
    if(!_collectionView){
        UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init];
        _collectionView = [[UICollectionView alloc]initWithFrame:self.superView.bounds collectionViewLayout:layout];
        [_collectionView registerClass:[LGPhotoCollectionCell class] forCellWithReuseIdentifier:@"cell"];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.scrollEnabled = NO;
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
    }
    return _collectionView;
}
-(UILabel *)remindLabel{
    if(!_remindLabel){
        _remindLabel = [UILabel lableWithText:@"上传图片" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _remindLabel;
}

-(UILabel *)remindSubLabel{
    if(!_remindSubLabel){
        _remindSubLabel = [UILabel lableWithText:@"请确保图片内容清晰可见" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _remindSubLabel;
}

@end

